<template>
  <div class="mnt-dialog form-container">
    <el-form ref="form" :model="formModel" label-width="160px" :rules="rules">
      <el-row style="text-align: center">
        <el-col :span="12" >
          <el-form-item label="所属模块:" prop="tmBasModuleId">
            <el-select v-model="formModel.tmBasModuleId" clearable filterable>
              <el-option v-for="item in moduleOptions" :key="item.tmBasModuleId" :label="item.moduleCode+'-'+item.moduleDesc" :value="item.tmBasModuleId"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="识别码:" prop="markCode">
            <el-input v-model="formModel.markCode"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row class="submit-area">
      <el-col :span="24">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="handleSubmit()">确定</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>

  import {mapGetters} from "vuex";

  export default {
    name: 'ModuleBscInfoMnt',
    props: ['pageType', 'editData'],
    data() {
      return {
        moduleOptions:[],
        formModel: {
          tmBasModuleId: '',
          markCode: '',
        },
        rules: {
        }
      }
    },
    computed: {
      ...mapGetters([
        'authorityList',
      ])
    },
    mounted() {
      this.getModule()
      this.init()
    },
    methods: {
      getModule(){
        const param = {pageNum:1,pageSize:9999}
        param.isDelete = '0'
        this.get('/tmBasModule/queryTmBasModule', param).then(res => {
          //设置业务权限
          const inCludeKeys = this.authorityList
          if(inCludeKeys.length>0){
            this.moduleOptions = res.list.filter(item => inCludeKeys.includes(item.tmBasModuleId))
          }else{
            this.moduleOptions = []
          }
        })
      },
      init() {
        this.$form = this.$refs.form
        const { pageType, editData, formModel } = this
        if (pageType !== 'add') {
          this.assignData(editData, formModel)
        }
        this.initRules()
      },
      initRules() {
        const REQUIRED_MSG = this.CONST.REQUIRED_MSG
        this.rules = {
          tmBasModuleId: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }],
          markCode: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }],
        }
        this.$nextTick(_ => {
          this.$form.clearValidate()
        })
      },
      handleSubmit() {
        this.$refs.form.validate(valid => {
          if (valid) {
            const { pageType, formModel } = this
            const param = { ...formModel }
            const operateType = pageType === 'edit' ? '02' : '01'
            param.operateType = operateType
            const url = '/trBasModuleFiledAudit/maintainTrBasModuleFiledAudit'
            const tip = pageType === 'edit' ? '修改成功！' : '新增成功！'
            this.post(url, param).then(res => {
              this.$info(tip, () => {
                this.$emit('mntSuc', res)
                this.closeDialog()
              })
            })
          }
        })
      },
      closeDialog() {
        this.$parent.$emit('update:visible', false)
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
